﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
using Microsoft.Reporting.WinForms;
using Iprojects.Data;
using System.Linq;

namespace Iprojects.Forms
{
    public partial class ReportByIDAndProject : Form
    {




        private Person currentPerson;
        ZakahEntities db = new ZakahEntities();
        //private Person currentPerson;
        
        public ReportByIDAndProject()
        {
            InitializeComponent();
         
    
     
           
        }
      
        private void button1_Click(object sender, EventArgs e)
        {
        
           
               // add new project event to family 
           
            int result = 0;
             //  oPerson.AddHomeFixesProject(txtAmount.Text,familyid,txtAddress.Text,dateFrom.Value.ToShortDateString(),txtNote.Text);
           if (result > 0)
           {
               //add a moslemFamilyProject

               //  oPerson.ad
               MessageBox.Show("تم اضافة المشروع بنجاح");
               //btnAddFamily.Enabled = false;
           }
    
        }

           void txtid_Leave(object sender, System.EventArgs e)
        {
           
             // check if there is id like that at table FamilyPerson
            //if have a relation in family person then
            bool isthereahusbandinsystem = false;
            if (txtid.Text.Length > 8)
            {
                currentPerson = db.Persons.FirstOrDefault(x => x.IDnum == txtid.Text);
               
            }

            if (null == currentPerson)
            {
                //  isthereahusbandinsystem
                MessageBox.Show("لم يتم العثور على الشخص");
                // clear id  
                txtid.Text = string.Empty;
                txtid.Focus();


            }
            else
            {
                        
                //btnAddFamily.Enabled =true;
                txtFullname.Text = currentPerson.FirstName + " " + currentPerson.FatherName + " " + currentPerson.LastName;
                /*List<Iprojects.Data.moslemFamilyProject> ff= .ToList<moslemFamilyProject>();*/
                var query = from p in db.moslemFamilyProjects.Where(x => x.familyID == currentPerson.FamilyID)
                         select p;        

                List<moslemFamilyProject>  ListFamilyMoslemproj = query.ToList<moslemFamilyProject>();

               var query2 = from p in db.FoodBoxProjects.Where(x => x.familyID == currentPerson.FamilyID) select p;
                       
                List<FoodBoxProject> ListFoodBoxmproj = query2.ToList<FoodBoxProject>();

                var query3 = from p in db.HomeFixesProjects.Where(x => x.familyID == currentPerson.FamilyID) select p;

                List<HomeFixesProject> ListHomeFix = query3.ToList<HomeFixesProject>();

                var query4 = from p in db.SchoolBagsProjects.Where(x => x.familyID == currentPerson.FamilyID) select p;

                List<SchoolBagsProject> ListSchoolBags = query4.ToList<SchoolBagsProject>();


              
                
               
               
            List<Person> ListPerson = new List<Person>();
                ListPerson.Add(currentPerson);
               
                this.reportViewer1.LocalReport.DataSources.Clear();
                this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetMoslemFamily", ListFamilyMoslemproj));
                this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetFoodBox", ListFoodBoxmproj));
                this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetPerson", ListPerson));
                this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetHomeFix", ListHomeFix));
                this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetSchoolBags", ListSchoolBags));
                
                //this.reportViewer1.Reset();
                //this.reportViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc");
               // ReportDataSource rds = new ReportDataSource("DataSet1",AllFamilies.GetAllProjects);
               // this.reportViewer1.LocalReport.DataSources = AllFamilies.GetAllProjects;

                //this.reportViewer1.DataBind(); 
               // reportmoslemFamilyProjectBindingSource.DataSource = AllFamilies.GetAllProjects; 
                // Below code demonstrate the Parameter passing method. Use only if you have parameters into the reports.

             
ReportParameter p1 = new ReportParameter("FullName", currentPerson.FirstName + " " + currentPerson.FatherName + " " + currentPerson.LastName);
ReportParameter p2 = new ReportParameter("PersonID", currentPerson.IDnum);
                
reportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1 ,p2});
reportViewer1.Visible = true;
                


                this.reportViewer1.RefreshReport();  
               

          
            }



        }

           private void ReportByDateAndProject_Load(object sender, EventArgs e)
           {

               this.reportViewer1.RefreshReport();
           }
           public static  DataTable createDataTableProjectMoslemFamily()
           {
               //
               // Here we create a DataTable with four columns.
               //
               DataTable table = new DataTable();
               table.Columns.Add("Dosage", typeof(int));
               table.Columns.Add("Drug", typeof(string));
               table.Columns.Add("Patient", typeof(string));
               table.Columns.Add("Date", typeof(DateTime));

               //
               // Here we add five DataRows.
               //
               table.Rows.Add(25, "Indocin", "David", DateTime.Now);
               table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
               table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
               table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
               table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
               return table;
           }

           private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
           {
              // MessageBox.Show(drpProject.SelectedValue.ToString());
           }

           private void reportViewer1_Load(object sender, EventArgs e)
           {

           }

        }

   
    }



